import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class WidgetNumOperating extends StatefulWidget {
  @override
  _widgetNumOperating createState() => _widgetNumOperating();
}

class _widgetNumOperating extends State<WidgetNumOperating> {
  int countNum = 0;

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      width: ScreenUtil().setWidth(165),
      margin: EdgeInsets.only(top: 5.0),
      decoration:
          BoxDecoration(border: Border.all(color: Colors.black12, width: 0.5)),
      child: Row(
        children: <Widget>[
          _addBtn(context),
          _count(),
          _reduceBtn(context),
        ],
      ),
    );
  }

  Widget _reduceBtn(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      height: ScreenUtil().setHeight(45),
      width: ScreenUtil().setWidth(45),
      decoration: BoxDecoration(
          color: Colors.white,
          border: Border(left: BorderSide(color: Colors.black12, width: 0.5))),
      child: InkWell(
        onTap: () {
          setState(() {
            countNum++;
          });
        },
        child: Text('+'),
      ),
    );
  }

  Widget _addBtn(BuildContext context) {
    return InkWell(
      onTap: () {
        if (countNum > 0) {
          setState(() {
            countNum--;
          });
        }
      },
      child: Container(
        alignment: Alignment.center,
        height: ScreenUtil().setHeight(45),
        width: ScreenUtil().setWidth(45),
        decoration: BoxDecoration(
            color: Colors.white,
            border:
                Border(right: BorderSide(color: Colors.black12, width: 0.5))),
        child: Text('-'),
      ),
    );
  }

  Widget _count() {
    return Container(
      alignment: Alignment.center,
      height: ScreenUtil().setHeight(45),
      width: ScreenUtil().setWidth(70),
      decoration: BoxDecoration(
        color: Colors.white,
      ),
      child: Text('${countNum}'),
    );
  }
}
